<template>
  <div class="global-config-view">
    <div class="page-header">
      <h1>全域配置</h1>
      <p class="page-desc">管理系统全局配置项，支持Key-Value格式存储</p>
    </div>

    <el-card class="config-card">
      <template #header>
        <div class="card-header">
          <span>配置管理</span>
          <span class="subtitle">管理系统的全局配置项</span>
        </div>
      </template>
      
      <!-- 按需加载：只有组件挂载后才加载数据 -->
      <KeyValueList ref="listRef" :auto-load="true" @refresh="handleRefresh" />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import KeyValueList from '../components/global-config/KeyValueList.vue';

const listRef = ref<InstanceType<typeof KeyValueList>>();

// 刷新列表
const handleRefresh = () => {
  // 可以在这里添加额外的刷新逻辑
  console.log('配置列表已刷新');
};

// 组件挂载时的处理
onMounted(() => {
  // 组件按需加载，不在这里主动加载数据
  // 数据加载由KeyValueList组件的autoLoad prop控制
  console.log('全域配置页面已加载');
});
</script>

<style scoped>
.global-config-view {
  padding: 20px;
  min-height: 100vh;
  background: var(--el-bg-color-page);
}

.page-header {
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 500;
  color: var(--el-text-color-primary);
}

.page-desc {
  margin: 0;
  font-size: 14px;
  color: var(--el-text-color-secondary);
}

.config-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.subtitle {
  font-size: 14px;
  color: var(--el-text-color-secondary);
}
</style>

